#include<iostream>
#include<cstring>

using namespace std;
char   a[100000001];

void qianzhuihe()
{
	int n,r;
	cin >> n >> r;
	int pos = 1;
	short int a[10000]; 
	bool fushu = false;
	if (n<0) {
		fushu = true;
		n = -1*n;
	}
	int s = n/r;
	int m = n%r;
	a[0] = m;
	while (s > 0)
	{		
		m = s%r;
		s = s/r;
		a[pos++] = m; 		
	}
	if (fushu) cout << -1;
	for (int i=0;i<pos;i++)
	{		
		if (a[pos-i-1]==10)
			cout << 'A';
		else if (a[pos-i-1]==11)
			cout << 'B';
		else if (a[pos-i-1]==12)
			cout << 'C';
		else if (a[pos-i-1]==13)
			cout << 'D';
		else if (a[pos-i-1]==14)
			cout << 'E';
		else if (a[pos-i-1]==15)
			cout << 'F';
		else 
			cout << a[pos-i-1] ;		
	}
	
	
	
}

int main()
{
	qianzhuihe();
	//diguis();
	return 0;	
} 
